<!DOCTYPE html>
<html>

	<head>
		<title>瘦吧门店管理平台</title>
		<meta http-equiv="Expires" CONTENT="0">
		<meta http-equiv="Cache-Control" CONTENT="no-cache">
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">
		<%include("/common/include.html"){}%>
		<script type="text/javascript" src="${cxt!}/sb/js/comet4j.js"></script>
	</head>
	<script type="text/javascript">
		$(function() {

			// 选项卡
			var mainTabs = $('#mainTabs');

			// 选项卡菜单
			var tabsMenu = $('#tabsMenu').menu(
					{
						onClick : function(item) {
							var curTabTitle = $(this).data('tabTitle');
							var type = $(item.target).attr('type');

							if (type === 'close') {
								var t = mainTabs.tabs('getTab', curTabTitle);
								if (t.panel('options').closable) {
									mainTabs.tabs('close', curTabTitle);
								}
								return;
							}

							var allTabs = mainTabs.tabs('tabs');
							var closeTabsTitle = [];

							$.each(allTabs, function() {
								var opt = $(this).panel('options');
								if (opt.closable && opt.title != curTabTitle
										&& type === 'closeOther') {
									closeTabsTitle.push(opt.title);
								} else if (opt.closable && type === 'closeAll') {
									closeTabsTitle.push(opt.title);
								}
							});

							for ( var i = 0; i < closeTabsTitle.length; i++) {
								mainTabs.tabs('close', closeTabsTitle[i]);
							}
						}
					});
			// 初始化选项卡
			mainTabs.tabs({
				fit : true,
				border : false,
				tools : [ {
					text : '最大化',
					iconCls : 'icon-arrowoutlonger',
					handler : function() {
						$('#mainLayout').layout("collapse", "north").layout("collapse", "west");
					}
				}, {
					text : '刷新',
					iconCls : 'icon-arrowrefresh',
					handler : refresh
				},{
					text : '操作',
					iconCls : 'icon-set',
					handler : function(e) {
						var winW = $(window).width();
						$('#menu').menu('show', {
							left: (winW-120)+"px",
							top: "102px"
						});
					}
				}],
				onContextMenu : function(e, title) {
					e.preventDefault();
					tabsMenu.menu('show', {
						left : e.pageX,
						top : e.pageY
					}).data('tabTitle', title);
				}
			});
			// 初始化添加默认主页
			var mainOpts = {
				fit: true,
				title: '管理中心',
				closable: false,
				border: false,
				//			iconCls : 'icon-feed',
				content: '<iframe id="mainFrame" name="mainFrame" src="${cxt!}/center" allowTransparency="true" style="border: 0; width: 100%; height: 99%;" frameBorder="0"></iframe>'
			};
			
			mainTabs.tabs('add', mainOpts);
		});
	</script>

	<body id="mainLayout" class="easyui-layout">
	
		<div data-options="region:'north',border: false" style="height: 62px; overflow: hidden;">
			<img src="${cxt!}/sb/img/head.png" / style="width: 100%;height: 62px;" >
		</div>
		<div data-options="region:'west',href:'',split:true" title="欢迎-${user.name! }" style="width: 200px; overflow: hidden;">
			<% include("/index/menu.html"){} %>
		</div>
		<div data-options="region:'center'" style="overflow: hidden;">
			<div id="mainTabs" class="easyui-tabs theme-tab-green-block" data-options="tabPosition:'top'"></div>
			<div id="menu" class="easyui-menu" style="width:120px;position">									
				<div onclick="toDetailAnnounce()">
					<span>我的通告</span>
				</div>
				<div class="menu-sep"></div>
				<div onclick="toPersonalInformation()">
					<span>个人资料</span>
				</div>
				<div class="menu-sep"></div>
				<div onclick="exit()">
					<span>安全退出</span>
				</div>
			</div>
		</div>
		<div data-options="region:'south',border:false" style="height: 30px; overflow: hidden; text-align: center;background-color: #f28338;">
			<p style="margin-top: 8px;color: #fff;">技术支持：太原市迅普高科电子科技有限公司&nbsp;&nbsp;&nbsp;电话：0351-7232123</p>
		</div>

		<div id="tabsMenu">
			<div data-options="iconCls:'icon-applicationdelete'" type="close">关闭</div>
			<div data-options="iconCls:'icon-cancel'" type="closeOther">关闭其他</div>
			<div data-options="iconCls:'icon-cross'" type="closeAll">关闭所有</div>
		</div>
		<script type="text/javascript">
			
			function nodeClick(title, url) {
				
				var mainTabs = $('#mainTabs');
				
				if (url) {
					var src = cxt + url;
					if (!sy.startWith(url, '/')) {
						src = cxt + url;
					}
					var opts = {
						title : title,
						closable : true,
// 						iconCls : node.iconCls,
						content : sy
								.formatString(
										'<iframe src="{0}" allowTransparency="true" style="border:0;width:100%;height:99%;" frameBorder="0"></iframe>',
										src),
						border : false,
						fit : true
					};
					if (mainTabs.tabs('exists', title)) {
						mainTabs.tabs('select', title);
						var current_tab = mainTabs.tabs('getSelected'); 
						mainTabs.tabs('update',{ 
						   tab:current_tab, 
						   options : { 
						     content :  sy
								.formatString(
										'<iframe src="{0}" allowTransparency="true" style="border:0;width:100%;height:99%;" frameBorder="0"></iframe>',
										src),
						   //或者 href : ''; 
						   } 
						}); 
					} else {
						ZENG.msgbox.show("正在加载...", 6, 1000000);
						mainTabs.tabs('add', opts);
					}
				}
			}
			function refresh(){
				ZENG.msgbox.show("正在加载...", 6, 1000000);
				var mainTabs = $('#mainTabs');
				var panel = mainTabs.tabs('getSelected').panel('panel');
				var frame = panel.find('iframe');
				try {
					if (frame.length > 0) {
						for ( var i = 0; i < frame.length; i++) {
							frame[i].contentWindow.document.write('');
							frame[i].contentWindow.close();
							var src = frame[i].src;
							var index = src.lastIndexOf("?");
							if(index != -1){
								frame[i].src = src.substr(0,index);
							}else{
								frame[i].src = src;
							}
						}
						if (navigator.userAgent.indexOf("MSIE") > 0) {// IE特有回收内存方法
							try {
								CollectGarbage();
							} catch (e) {
							}
						}
					}
				} catch (e) {
				}
			}
			
			// 右下角弹窗提示
	        function slideMsg(str){
				if(str.indexOf('新的通知')>= 0){
					var str1=str.split("|")[0];
					var str2=str.split("|")[1];
					
				str ="<a  onclick=toXq1('"+str2+"') >"+str1+"</a>";
					 $.messager.show({
			                title:'操作提示',
			                msg:str,
			                timeout:1500*30,
			                showType:'slide'
			            });
	        	}else{
	        		 $.messager.show({
	 	                title:'操作提示',
	 	                msg:str,
	 	                timeout:1500,
	 	                showType:'slide'
	 	            });
	        	} 
	           
	        }
	      //安全退出
			function exit(){
				window.location.href = cxt + "/login/logout";
			}
			function alterPassword(){
				window.location.href = "";
			}
		</script>
		<script type="text/javascript">
		
		    var websocket = null;
		    //判断当前浏览器是否支持WebSocket
		    if ('WebSocket' in window) {
		        websocket = new WebSocket("ws://127.0.0.1:8080/shouba2.0/websocket/${user.username! }");
		    } else {
		        alert('当前浏览器 Not support websocket')
		    }
		
		    //连接发生错误的回调方法
		    websocket.onerror = function () {
		        setMessageInnerHTML("WebSocket连接发生错误");
		    };
		
		    //连接成功建立的回调方法
		    websocket.onopen = function () {
		        setMessageInnerHTML("WebSocket连接成功");
		    }
		
		    //接收到消息的回调方法
		    websocket.onmessage = function (event) {
		        setMessageInnerHTML(event.data);
		    	
		    }
		
		    //连接关闭的回调方法
		    websocket.onclose = function () {
		        setMessageInnerHTML("WebSocket连接关闭");
		    }
		
		    //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
		    window.onbeforeunload = function () {
		        closeWebSocket();
		    }
		
		    //将消息显示在网页上
		    function setMessageInnerHTML(innerHTML) {
		    	slideMsg(innerHTML);
		//         document.getElementById('message').innerHTML += innerHTML + '<br/>';
		    }
		
		    //关闭WebSocket连接
		    function closeWebSocket() {
		        websocket.close();
		    }
		
		    //发送消息
		    function send() {
		        var message = document.getElementById('text').value;
		        websocket.send(message);
		        websocket.send(JSON.stringify({
		        	  to: "client2",
		        	  data: "foo"
		        	}));
		    }
		    //点击操作里的公告，跳转到详细公告页面
		    function toDetailAnnounce(){
				parent.window.nodeClick("我的通告", "/detailAnnounce");
			}
		    //点击操作里的个人资料，跳转到个人资料设置页面
		    function toPersonalInformation(){
				parent.window.nodeClick("个人资料设置", "/personalInformation");
			}
		  
		    function toXq1(id){
		    	parent.window.nodeClick("公告详情", "/detailAnnounce/check?ids="+id);
		    }
		</script>
	</body>

</html>